package se.webbzon.oschi01.utilities;

import java.util.Random;

public class ArrayUtils {
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns one random element from the given array of elements. **/
	@SafeVarargs
	public static <T> T random(T ... elements) {
		int index = (int) (Math.random() * elements.length);
		return elements[index];
	}
	
	/** Shuffles the given array. **/
	public static <T> void shuffle(T[] array) {
		Random rnd = new Random();
		for (int i = array.length - 1; i > 0; i--) {
			int index = rnd.nextInt(i + 1);
			T e = array[index];
			array[index] = array[i];
			array[i] = e;
		}
	}

}
